/**
 * Created by gdx on 2017/3/6.
 */
!function () {
    "use strict";
    var Drag = {
        isDrag: false,
        newClass: function (obj) {
            obj = obj || {};
            this.init.prototype = Drag;
            return new this.init(obj);
        },
        init: function (options) {
            this.options = options;
            this.options.dragStyle(this.options.element);
            this.bindTouch();
        },
        bindTouch: function () {
            var _this = this;
            $(this.options.element).on("touchstart", function (e) {
                _this.x = this.offsetLeft;
                _this.y = this.offsetTop;
                _this.mx = e.originalEvent.changedTouches[0].pageX;
                _this.my = e.originalEvent.changedTouches[0].pageY;
                _this.options.dragStart(this);
                $(this).on("touchmove", function (e) {
                    $(this).css({
                        left: e.originalEvent.changedTouches[0].pageX - _this.mx + _this.x,
                        top: e.originalEvent.changedTouches[0].pageY - _this.my + _this.y
                    })
                    _this.options.dragging(this);
                    e.preventDefault();
                });

                $(this).on("touchend", function (e) {
                    $(this).off("touchmove touchend")
                    _this.options.dragEnd(this);
                    e.preventDefault();
                });
                e.preventDefault();
            });
        }
    };
    window.Drag = Drag;
}();


